#include "deToken.h"

int Decode_Jwt(char* issuer,char* subject,char* jwt_str)
{
    //0 success 1 failed
    struct l8w8jwt_decoding_params params;
    l8w8jwt_decoding_params_init(&params);

    params.alg = L8W8JWT_ALG_HS256;

    params.jwt = jwt_str;
    params.jwt_length = strlen(jwt_str);

    params.verification_key = (unsigned char*)"luyimin";
    params.verification_key_length = strlen("luyimin");

    params.validate_iss = issuer;
    params.validate_sub = subject;

    params.validate_exp = 1;
    params.exp_tolerance_seconds = (uint8_t)60;

    params.validate_iat = 1;
    params.iat_tolerance_seconds = (uint8_t)60;

    enum l8w8jwt_validation_result validation_result;

    int decode_result = l8w8jwt_decode(&params,&validation_result,NULL,NULL);
    if(decode_result == L8W8JWT_SUCCESS && validation_result == L8W8JWT_VALID)
    {
        return 0;
    }
    return -1;
}